package org.phalanx.gwt.client.graphics.map;

import java.util.ArrayList;
import java.util.Iterator;

public class PhalanxTileSetReader {
	private MapTileSet tileset;
	private ArrayList<String> tileRefList;
	
	public PhalanxTileSetReader(){
		tileRefList = new ArrayList<String>();
	}
	
	public PhalanxTileSetReader(ArrayList<String> referenceList){
		setTileSetReferenceList(referenceList);
	}
	
	public void setTileSetReferenceList(ArrayList<String> referenceList){
		tileRefList = referenceList;
	}
	
	public void readInTileSetInfo(){
		tileset = new MapTileSet();
		Iterator<String> i = tileRefList.iterator();
		
		while(i.hasNext()){
			String listItem = i.next();
			listItem = listItem.substring(1, listItem.length() - 1);
			String[] properties = listItem.split("!");
			
			if (properties.length == 3){
				MapTile t = new MapTile();
				
				PhalanxMapTerrain terrain = new PhalanxMapTerrain();
				terrain.setTerrainType(properties[1]);
				
				t.setTerrain(terrain);
				t.setImageReference(properties[2]);
				
				tileset.setMapTile(properties[0], t);
			}
		}
	}
	
	public MapTileSet getMapTileSet(){
		return tileset;
	}
}
